package com.yonyou.pmclouds.basecom.rmiimpl;

import com.alibaba.dubbo.config.annotation.Service;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.entity.AdditionalPropertiesVOWrapper;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.rmiitf.ListCommonPropertiesService;
import com.yonyou.pmclouds.discuss.itf.DiscussInternalOperation;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

@Service(version = ApplicationConsts.APPLICATION_VERSION, interfaceClass = ListCommonPropertiesService.class)
public class ListCommonPropertiesServiceImpl implements ListCommonPropertiesService {
    @Autowired
    private DiscussInternalOperation discussOperation;

    @Override
    public Map<String, Map<String, Object>> fetchAdditionProperties(String[] ids) throws BusinessException {
        if (ArrayUtils.isEmpty(ids)) {
            return null;
        }
        Map<String, Map<String, Object>> result = new HashMap<>(ids.length);
        // 获取评论数
        Map<String, Integer> discussCounts = discussOperation.countDiscussion(ids);
        if (discussCounts != null) {
            for (Map.Entry<String, Integer> entry : discussCounts.entrySet()) {
                String s=entry.getKey();
                Integer i=entry.getValue();

                Map<String, Object> prop = new HashMap<>(1);
                prop.put(AdditionalPropertiesVOWrapper.COMMENT_COUNT, entry.getValue());
                result.put(entry.getKey(), prop);
            }
        }
        return result;
    }
}
